home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / rpm / rpmmacro.h < prev    next >
Encoding:
C/C++ Source or Header  |  2008-10-22  |  7.7 KB  |  256 lines

  1. #ifndef _H_MACRO_
  2. #define    _H_MACRO_
  3.  
  4. /** \ingroup rpmio
  5.  * \file rpmio/rpmmacro.h
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10.  
  11. /*! The structure used to store a macro. */
  12. typedef /*@abstract@*/ struct MacroEntry_s {
  13.     struct MacroEntry_s *prev;/*!< Macro entry stack. */
  14.     const char *name;    /*!< Macro name. */
  15.     const char *opts;    /*!< Macro parameters (a la getopt) */
  16.     const char *body;    /*!< Macro body. */
  17.     int    used;        /*!< No. of expansions. */
  18.     int    level;        /*!< Scoping level. */
  19. } * MacroEntry;
  20.  
  21. /*! The structure used to store the set of macros in a context. */
  22. typedef /*@abstract@*/ struct MacroContext_s {
  23. /*@owned@*//*@null@*/ MacroEntry *macroTable;    /*!< Macro entry table for context. */
  24.     int    macrosAllocated;/*!< No. of allocated macros. */
  25.     int    firstFree;    /*!< No. of macros. */
  26. } * MacroContext;
  27.  
  28. /*@-redecl@*/
  29. /*@checked@*/
  30. extern MacroContext rpmGlobalMacroContext;
  31.  
  32. /*@checked@*/
  33. extern MacroContext rpmCLIMacroContext;
  34. /*@=redecl@*/
  35.  
  36. /** \ingroup rpmrc
  37.  * List of macro files to read when configuring rpm.
  38.  * This is a colon separated list of files. URI's are permitted as well,
  39.  * identified by the token '://', so file paths must not begin with '//'.
  40.  */
  41. /*@-redecl@*/
  42. /*@observer@*/ /*@checked@*/
  43. extern const char * macrofiles;
  44. /*@=redecl@*/
  45.  
  46. /**
  47.  * Markers for sources of macros added throughout rpm.
  48.  */
  49. #define    RMIL_DEFAULT    -15
  50. #define    RMIL_MACROFILES    -13
  51. #define    RMIL_RPMRC    -11
  52.  
  53. #define    RMIL_CMDLINE    -7
  54. #define    RMIL_TARBALL    -5
  55. #define    RMIL_SPEC    -3
  56. #define    RMIL_OLDSPEC    -1
  57. #define    RMIL_GLOBAL    0
  58.  
  59. #ifdef __cplusplus
  60. extern "C" {
  61. #endif
  62.  
  63. /**
  64.  * Print macros to file stream.
  65.  * @param mc        macro context (NULL uses global context).
  66.  * @param fp        file stream (NULL uses stderr).
  67.  */
  68. void    rpmDumpMacroTable    (/*@null@*/ MacroContext mc,
  69.                     /*@null@*/ FILE * fp)
  70.     /*@globals rpmGlobalMacroContext, fileSystem @*/
  71.     /*@modifies *fp, fileSystem @*/;
  72.  
  73. /**
  74.  * Return URL path(s) from a (URL prefixed) pattern glob.
  75.  * @param patterns    glob pattern
  76.  * @retval *argcPtr    no. of paths
  77.  * @retval *argvPtr    array of paths (malloc'd contiguous blob)
  78.  * @return        0 on success
  79.  */
  80. int rpmGlob(const char * patterns, /*@out@*/ int * argcPtr,
  81.         /*@out@*/ const char *** argvPtr)
  82.     /*@globals fileSystem, internalState @*/
  83.     /*@modifies *argcPtr, *argvPtr, fileSystem, internalState @*/;
  84.  
  85. /**
  86.  * Expand macro into buffer.
  87.  * @deprecated Use rpmExpand().
  88.  * @todo Eliminate from API.
  89.  * @param spec        cookie (unused)
  90.  * @param mc        macro context (NULL uses global context).
  91.  * @retval sbuf        input macro to expand, output expansion
  92.  * @param slen        size of buffer
  93.  * @return        0 on success
  94.  */
  95. int    expandMacros    (/*@null@*/ void * spec, /*@null@*/ MacroContext mc,
  96.                 /*@in@*/ /*@out@*/ char * sbuf,
  97.                 size_t slen)
  98.     /*@globals rpmGlobalMacroContext, h_errno, fileSystem @*/
  99.     /*@modifies *sbuf, rpmGlobalMacroContext, fileSystem @*/;
  100.  
  101. /**
  102.  * Add macro to context.
  103.  * @deprecated Use rpmDefineMacro().
  104.  * @param mc        macro context (NULL uses global context).
  105.  * @param n        macro name
  106.  * @param o        macro paramaters
  107.  * @param b        macro body
  108.  * @param level        macro recursion level (0 is entry API)
  109.  */
  110. void    addMacro    (/*@null@*/ MacroContext mc, const char * n,
  111.                 /*@null@*/ const char * o,
  112.                 /*@null@*/ const char * b, int level)
  113.     /*@globals rpmGlobalMacroContext @*/
  114.     /*@modifies mc, rpmGlobalMacroContext @*/;
  115.  
  116. /**
  117.  * Delete macro from context.
  118.  * @param mc        macro context (NULL uses global context).
  119.  * @param n        macro name
  120.  */
  121. void    delMacro    (/*@null@*/ MacroContext mc, const char * n)
  122.     /*@globals rpmGlobalMacroContext @*/
  123.     /*@modifies mc, rpmGlobalMacroContext @*/;
  124.  
  125. /**
  126.  * Define macro in context.
  127.  * @param mc        macro context (NULL uses global context).
  128.  * @param macro        macro name, options, body
  129.  * @param level        macro recursion level (0 is entry API)
  130.  * @return        @todo Document.
  131.  */
  132. int    rpmDefineMacro    (/*@null@*/ MacroContext mc, const char * macro,
  133.                 int level)
  134.     /*@globals rpmGlobalMacroContext, h_errno @*/
  135.     /*@modifies mc, rpmGlobalMacroContext @*/;
  136.  
  137. /**
  138.  * Load macros from specific context into global context.
  139.  * @param mc        macro context (NULL does nothing).
  140.  * @param level        macro recursion level (0 is entry API)
  141.  */
  142. void    rpmLoadMacros    (/*@null@*/ MacroContext mc, int level)
  143.     /*@globals rpmGlobalMacroContext @*/
  144.     /*@modifies rpmGlobalMacroContext @*/;
  145.  
  146. /**
  147.  * Load macro context from a macro file.
  148.  * @param mc        (unused)
  149.  * @param fn        macro file name
  150.  */
  151. int    rpmLoadMacroFile(/*@null@*/ MacroContext mc, const char * fn)
  152.     /*@globals rpmGlobalMacroContext,
  153.         h_errno, fileSystem, internalState @*/
  154.     /*@modifies mc, rpmGlobalMacroContext, fileSystem, internalState @*/;
  155.  
  156. /**
  157.  * Initialize macro context from set of macrofile(s).
  158.  * @param mc        macro context
  159.  * @param macrofiles    colon separated list of macro files (NULL does nothing)
  160.  */
  161. void    rpmInitMacros    (/*@null@*/ MacroContext mc, const char * macrofiles)
  162.     /*@globals rpmGlobalMacroContext, rpmCLIMacroContext,
  163.         h_errno, fileSystem, internalState @*/
  164.     /*@modifies mc, rpmGlobalMacroContext, fileSystem, internalState @*/;
  165.  
  166. /**
  167.  * Destroy macro context.
  168.  * @param mc        macro context (NULL uses global context).
  169.  */
  170. void    rpmFreeMacros    (/*@null@*/ MacroContext mc)
  171.     /*@globals rpmGlobalMacroContext @*/
  172.     /*@modifies mc, rpmGlobalMacroContext @*/;
  173.  
  174. typedef enum rpmCompressedMagic_e {
  175.     COMPRESSED_NOT        = 0,    /*!< not compressed */
  176.     COMPRESSED_OTHER        = 1,    /*!< gzip can handle */
  177.     COMPRESSED_BZIP2        = 2,    /*!< bzip2 can handle */
  178.     COMPRESSED_ZIP        = 3,    /*!< unzip can handle */
  179.     COMPRESSED_LZMA        = 4    /*!< lzma can handle */
  180. } rpmCompressedMagic;
  181.  
  182. /**
  183.  * Return type of compression used in file.
  184.  * @param file        name of file
  185.  * @retval compressed    address of compression type
  186.  * @return        0 on success, 1 on I/O error
  187.  */
  188. int    isCompressed    (const char * file,
  189.                 /*@out@*/ rpmCompressedMagic * compressed)
  190.     /*@globals h_errno, fileSystem, internalState @*/
  191.     /*@modifies *compressed, fileSystem, internalState @*/;
  192.  
  193. /**
  194.  * Return (malloc'ed) concatenated macro expansion(s).
  195.  * @param arg        macro(s) to expand (NULL terminates list)
  196.  * @return        macro expansion (malloc'ed)
  197.  */
  198. char * rpmExpand    (/*@null@*/ const char * arg, ...)
  199.     /*@globals rpmGlobalMacroContext, h_errno @*/
  200.     /*@modifies rpmGlobalMacroContext @*/;
  201.  
  202. /**
  203.  * Canonicalize file path.
  204.  * @param path        path to canonicalize (in-place)
  205.  * @return        canonicalized path (malloc'ed)
  206.  */
  207. /*@null@*/
  208. char * rpmCleanPath    (/*@returned@*/ /*@null@*/ char * path)
  209.     /*@modifies *path @*/;
  210.  
  211. /**
  212.  * Return (malloc'ed) expanded, canonicalized, file path.
  213.  * @param path        macro(s) to expand (NULL terminates list)
  214.  * @return        canonicalized path (malloc'ed)
  215.  */
  216. /*@-redecl@*/ /* LCL: shrug */
  217. const char * rpmGetPath    (/*@null@*/ const char * path, ...)
  218.     /*@globals rpmGlobalMacroContext, h_errno @*/
  219.     /*@modifies rpmGlobalMacroContext @*/;
  220. /*@=redecl@*/
  221.  
  222. /**
  223.  * Merge 3 args into path, any or all of which may be a url.
  224.  * The leading part of the first URL encountered is used
  225.  * for the result, other URL prefixes are discarded, permitting
  226.  * a primitive form of URL inheiritance.
  227.  * @param urlroot    root URL (often path to chroot, or NULL)
  228.  * @param urlmdir    directory URL (often a directory, or NULL)
  229.  * @param urlfile    file URL (often a file, or NULL)
  230.  * @return        expanded, merged, canonicalized path (malloc'ed)
  231.  */
  232. /*@-redecl@*/ /* LCL: shrug */
  233. const char * rpmGenPath    (/*@null@*/ const char * urlroot,
  234.             /*@null@*/ const char * urlmdir,
  235.             /*@null@*/ const char * urlfile)
  236.     /*@globals rpmGlobalMacroContext, h_errno @*/
  237.     /*@modifies rpmGlobalMacroContext @*/;
  238. /*@=redecl@*/
  239.  
  240. /**
  241.  * Return macro expansion as a numeric value.
  242.  * Boolean values ('Y' or 'y' returns 1, 'N' or 'n' returns 0)
  243.  * are permitted as well. An undefined macro returns 0.
  244.  * @param arg        macro to expand
  245.  * @return        numeric value
  246.  */
  247. int    rpmExpandNumeric (const char * arg)
  248.     /*@globals rpmGlobalMacroContext, h_errno @*/
  249.     /*@modifies rpmGlobalMacroContext @*/;
  250.  
  251. #ifdef __cplusplus
  252. }
  253. #endif
  254.  
  255. #endif    /* _H_ MACRO_ */
  256.